package com.atguigu.dga.governance.assessor.calc;

import com.atguigu.dga.dolphinscheduler.bean.TDsTaskInstance;
import com.atguigu.dga.dolphinscheduler.service.TDsTaskInstanceService;
import com.atguigu.dga.governance.assessor.Assessor;
import com.atguigu.dga.governance.bean.AssessParam;
import com.atguigu.dga.governance.bean.GovernanceAssessDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.math.BigDecimal;
import java.net.URISyntaxException;
import java.text.ParseException;
import java.util.List;

/**
 * ClassName: TableTaskFailAssessor
 * Package: com.atguigu.dga.governance.assessor.calc
 * Description:
 *
 * @Author:
 * @Create: 2024/3/20 09:32
 * @Version: 1.0
 */
@Component("TABLE_TASK_FAIL")
public class TableTaskFailAssessor extends Assessor {
    @Autowired
    TDsTaskInstanceService tDsTaskInstanceService;
    @Override
    public void checkProblem(AssessParam assessParam, GovernanceAssessDetail governanceAssessDetail) throws ParseException, URISyntaxException, IOException, InterruptedException {
        // 检查是否有报错 DS中当前表当前考评日期是否有状态为6的
        // tDsTaskInstanceService 中写方法
        String name = assessParam.getTableMetaInfo().getSchemaName() + "." + assessParam.getTableMetaInfo().getTableName();
        String assessDate = assessParam.getAssessDate();
        List<TDsTaskInstance> failTdsTaskInstanceList = tDsTaskInstanceService.getFailTdsTaskInstanceList(name, assessDate);

        if(failTdsTaskInstanceList.size() > 0) {
            governanceAssessDetail.setAssessScore(BigDecimal.ZERO);
            governanceAssessDetail.setAssessProblem("计算中有报错");
        }
    }
}
